package com.atzongmaotan.reggie.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * ClassName:    MyMetaObjectHandler
 * Package:  com.atzongmaotan.common
 * Description:
 *
 * @Author: interface
 * @Create: 2024/6/12 - 下午11:05
 * @Version: v1.0
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("创建时填充公共字段");
        metaObject.setValue("createTime", LocalDateTime.now());
        metaObject.setValue("updateTime", LocalDateTime.now());
        Long userId = BaseContext.getCurrentUserId();
        metaObject.setValue("createUser", userId);
        metaObject.setValue("updateUser", userId);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("更新时填充公共字段");
        Long userId = BaseContext.getCurrentUserId();
        metaObject.setValue("updateTime", LocalDateTime.now());
        metaObject.setValue("updateUser", userId);

    }
}
